<!--
 * @Descripttion:分时销售报表
 * @Author: 森哥
 * @Date: 2022-11-08 14:42:46
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2025-09-22 11:19:27
-->
<template>
  <div>
    <div class="time-division-card-box">
      <!-- 骨架屏 -->
      <div v-if="loading" class="skeleton-container">
        <!-- 标题骨架 -->
        <div class="skeleton-title"></div>
        <div class="skeleton-description"></div>

        <!-- 基本信息骨架 -->
        <div class="skeleton-info">
          <div class="skeleton-info-item"></div>
          <div class="skeleton-info-item"></div>
        </div>

        <!-- 表头骨架 -->
        <div class="skeleton-table-header">
          <div class="skeleton-cell"></div>
          <div class="skeleton-cell"></div>
          <div class="skeleton-cell"></div>
        </div>
        <div class="skeleton-line"></div>

        <!-- 列表骨架 -->
        <div class="skeleton-list">
          <div v-for="i in 5" :key="i" class="skeleton-list-item">
            <div class="skeleton-cell"></div>
            <div class="skeleton-cell"></div>
            <div class="skeleton-cell"></div>
          </div>
        </div>

        <!-- 按钮骨架 -->
        <div class="skeleton-button"></div>
      </div>

      <!-- 实际内容 -->
      <div v-else>
        <!-- 餐厅名字 -->
        <div class="title">{{ timeList.shopName }}</div>
        <div class="description">【分时销售报表】</div>
        <!-- 时间 -->
        <div class="desc-item">
          <div>{{ timeList.time }}</div>
          <span></span>
        </div>
        <!-- 桌台 -->
        <div class="desc-item">
          <div>桌台：{{ timeList.deskName }}（{{ timeList.capacity }}人）</div>
          <span></span>
        </div>
        <!-- 表头 -->
        <div class="desc-item">
          <div>时间</div>
          <span>笔数</span>
          <div>金额</div>
        </div>
        <div class="desc-line"></div>
        <!-- 分时销售列表 -->
        <div class="loop-list-box">
          <div v-for="item in timeList.list" class="list-box" :key="item.id">
            <div class="list-left-box">{{ item.time }}</div>
            <div class="list-center-box">{{ item.num }}</div>
            <div class="list-right-box">&yen;{{ item.total_money }}</div>
          </div>
        </div>

        <div class="btn-box">
          <span class="print-btn" @click="handlePrint">打印</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { timeReport } from '@/api/time.ts'
import { ElMessage } from 'element-plus'

// 定义props
const props = defineProps({
  // 分时销售列表
  timeList: {
    type: Object,
    default: {}
  },
  timeReportId: {
    type: String,
    default: ''
  },
  loading: {
    type: Boolean,
    default: false
  }
})

// 打印方法
async function handlePrint() {
  try {
    await timeReport({
      desk_id: props.timeReportId,
      print: '1'
    })
    ElMessage.success('推送打印成功')
  } catch (error) {
    ElMessage.error('打印失败: ' + error.message)
  }
}
</script>

<style lang="scss" scoped>
.time-division-card-box {
  width: 420px;
  height: 986px;
  background: #ffffff;
  border-radius: 20px;
  box-shadow: 3px 0px 24px 0px rgba(0, 0, 0, 0.16);
  box-sizing: border-box;
  padding: 30px;
  .title {
    font-size: 20px;
    font-family:
      PingFang SC,
      PingFang SC-Bold;
    font-weight: 700;
    text-align: center;
    color: #333333;
  }
  .description {
    font-size: 16px;
    font-family:
      PingFang SC,
      PingFang SC-Bold;
    font-weight: 700;
    text-align: center;
    color: #333333;
    margin: 10px 0;
  }
  .desc-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 10px;
    font-size: 14px;
    font-family:
      PingFang SC,
      PingFang SC-Bold;
    font-weight: 700;
    color: #333333;
  }
  .loop-list-box {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    height: 700px;
    .list-box {
      font-size: 14px;
      font-family:
        PingFang SC,
        PingFang SC-Bold;
      font-weight: 700;
      color: #333333;
      display: flex;
      align-items: center;
      margin-top: 10px;
      .list-left-box {
        width: 33%;
        display: flex;
        justify-content: flex-start;
      }
      .list-center-box {
        width: 33%;
        display: flex;
        justify-content: center;
      }
      .list-right-box {
        width: 33%;
        display: flex;
        justify-content: flex-end;
      }
    }
  }

  //滚动条整体的大小
  .loop-list-box::-webkit-scrollbar {
    width: 6px !important;
    height: 0 !important;
  }
  //滚动条里滑动的滑块
  .loop-list-box::-webkit-scrollbar-thumb {
    height: 200px !important;
    background: #d2d2d2 !important;
    border-radius: 3px !important;
  }
  //滚动条底层样式
  .loop-list-box::-webkit-scrollbar-track {
    display: none !important;
  }
  .btn-box {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 34px;
    .print-btn {
      width: 360px;
      height: 52px;
      background: #7c0a03;
      border-radius: 20px;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 18px;
      font-family:
        PingFang SC,
        PingFang SC-Regular;
      font-weight: 400;
      color: #ffffff;
      cursor: pointer;
    }
  }
  .desc-line {
    width: 360px;
    height: 1px;
    background: #e2e2e2;
    margin-top: 10px;
  }
  .desc-title {
    font-size: 16px;
    font-family:
      PingFang SC,
      PingFang SC-Bold;
    font-weight: 700;
    text-align: center;
    color: #333333;
    margin: 20px 0 10px 0;
  }
  .address-phone-box {
    margin-top: 50px;
    font-size: 14px;
    font-family:
      PingFang SC,
      PingFang SC-Regular;
    font-weight: 400;
    text-align: center;
    color: #333333;
    line-height: 24px;
    > div {
      margin-bottom: 10px;
    }
  }
}

// 骨架屏样式
.skeleton-container {
  height: 100%;
  width: auto !important;
  padding: 0 !important;
  overflow: hidden;
  box-sizing: border-box;

  .skeleton-title {
    height: 20px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
    margin-bottom: 8px;
    width: 20%;
    margin: 0 auto 8px;
  }

  .skeleton-description {
    height: 16px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
    margin-bottom: 15px;
    width: 30%;
    margin: 0 auto 15px;
  }

  .skeleton-info {
    margin-bottom: 15px;

    .skeleton-info-item {
      height: 14px;
      background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
      background-size: 200% 100%;
      animation: skeleton-loading 1.5s infinite;
      border-radius: 4px;
      margin-bottom: 8px;
      width: 90%;
    }
  }

  .skeleton-table-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;

    .skeleton-cell {
      height: 14px;
      background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
      background-size: 200% 100%;
      animation: skeleton-loading 1.5s infinite;
      border-radius: 4px;
      width: 28%;
    }
  }

  .skeleton-list {
    margin-bottom: 20px;
    max-height: 500px;
    overflow: hidden;

    .skeleton-list-item {
      display: flex;
      justify-content: space-between;
      margin-bottom: 6px;

      .skeleton-cell {
        height: 12px;
        background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
        background-size: 200% 100%;
        animation: skeleton-loading 1.5s infinite;
        border-radius: 4px;
        width: 20%;
      }
    }
  }

  .skeleton-button {
    height: 45px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 20px;
    width: 280px;
    margin: 20px auto 0;
  }

  .skeleton-line {
    width: 70%;
    height: 1px;
    background: #e2e2e2;
    margin: 8px auto;
  }
}

@keyframes skeleton-loading {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}
</style>
